/**
  * Copyright (c) CSIRO Australia, 2009
  *
  * @author $Author: jia020 $
  * @version $Id: PdspLogger.java 643 2009-05-20 00:20:55Z jia020 $
  */
package au.csiro.nt.pdsp.util;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author jia020
 *
 */
public class PdspLogger {
	public void logWorkflow(int type ,int workflowid,String status,String log) {
		String sSql = "select logs from workflow where workflowid = " + workflowid;
		ResultSet rs = Config.getInstance().mysql.execSelect(sSql);
		try {	
			if (rs != null && rs.next()) {
				String logs = rs.getString("logs");
				logs = logs + ("-" + log);
				sSql = "update workflow set status = '" + status + "', logs = '" + logs + "' where workflowid = " + workflowid;
				Config.getInstance().mysql2.execUpdate(sSql);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	finally {
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public void logIMS(int type,int workflowid,String status) {
		String sSql = "update ims set status = '" + status + "' where workflowid = " + workflowid;
		Config.getInstance().mysql2.execUpdate(sSql);
	}
	
	public void logTask(int type,int taskid,String status,String log) {
		String sSql = "select logs from task where taskid = " + taskid;
		ResultSet rs = Config.getInstance().mysql.execSelect(sSql);
		try {	
			if (rs != null && rs.next()) {
				String logs = rs.getString("logs");
				logs = logs + ("-" + log);
				sSql = "update task set status = '" + status + "',logs = '" + logs + "' where taskid = " + taskid;
				Config.getInstance().mysql2.execUpdate(sSql);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	finally {
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}		
	}	
	
}
